//
//  CarModel.m
//  快速循环取值
//
//  Created by 岚海网络 on 2019/3/22.
//  Copyright © 2019年 ljm. All rights reserved.
//

#import "CarModel.h"

@implementation CarModel

+ (NSArray<CarGroup *> *)cars {
    
    NSArray *plistArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cars_total" ofType:@"plist"]];
    
    NSMutableArray *carsArray = [[NSMutableArray alloc] init];
    for (NSDictionary *dic in plistArray) {
        
        CarGroup *group = [[CarGroup alloc] init];
        group.prefix = dic[@"title"];
        
        NSArray<NSDictionary *> *tempCar = [NSArray array];
        tempCar = dic[@"cars"];
        
        NSMutableArray<CarModel *> *modelArray = [NSMutableArray array];
        for (NSDictionary *dict in tempCar) {
            CarModel *model = [[CarModel alloc] init];
            model.name = dict[@"name"];
            model.icon = dict[@"icon"];
            
            [modelArray addObject:model];
        }
        
        group.cars = [modelArray copy];
        [carsArray addObject:group];
    }
    
    return carsArray;
    
}

@end
